"""
功能：定义公共的启动driver，为后期用例提供统一的启动参数和方法
编写人：guodan
编写日期：2021年12月28日
实现步骤：

    1-导包
    2-定义启动参数
    3-启动driver
    4-return driver对象给其他方法使用


"""

from appium import webdriver
import time
from selenium.webdriver.common.by import By
from common.logs import logger
from common.readConfig import ReadConfig

rc = ReadConfig()
class Driver():
    def __init__(self):
        """
        初始化实例属性
        """
        self.devicename = rc.getdata('APP','ip') + ':' + rc.getdata('APP','port')
        self.platformName = rc.getdata('APP','platformName')
        self.platformVersion = rc.getdata('APP','platformVersion')
        self.appPackage = rc.getdata('APP','appPackage')
        self.appActivity = rc.getdata('APP','appActivity')
        self.noReset = rc.getdata('APP','noReset')
        self.unicodeKeyboard = rc.getdata('APP','unicodeKeyboard')
        self.appiumServer = rc.get_server('ip') + ':' + rc.get_server('port')
        logger.info('初始化完成driver配置信息')

    def startUp(self):
        """
        启动driver，返回driver对象
        :return:
        """
        dic = {
            'deviceName':self.devicename,
            'platformName':self.platformName,
            'platformVersion':self.platformVersion,
            'appPackage':self.appPackage,
            'appActivity':self.appActivity,
            'noReset':self.noReset,
            'unicodeKeyboard':self.unicodeKeyboard
        }
        driver = webdriver.Remote('http://' + self.appiumServer +'/wd/hub',dic)
        time.sleep(5)
        logger.info('app start successful,and return the driver ')
        return driver



if __name__ == '__main__':
    dr = Driver()
    dr.startUp()